/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.pool.DruidPooledPreparedStatement;
import com.alibaba.druid.pool.DruidPooledResultSet;
import com.alibaba.druid.pool.DruidPooledStatement;
import java.sql.ResultSet;



/**
 *
 * @author Administrator
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     * @throws java.lang.Exception
     */
    public static void main(String[] args) throws Exception{
        // TODO code application logic here
        DruidDataSourceUtil data_source_util = new DruidDataSourceUtil();
        DruidDataSource data_source = data_source_util.getDataSource();
        String sql = "select * from admin where id = 1";
        String update = "update admin set user_name = ? where id=1 ";
        DruidPooledConnection conn = data_source_util.getDruidConnection(data_source);
        
        DruidPooledStatement statement = (DruidPooledStatement)conn.createStatement();
        DruidPooledPreparedStatement pre_sql = (DruidPooledPreparedStatement) conn.prepareStatement(update);
        pre_sql.setString(1, "xox9001");
        pre_sql.executeUpdate();
        
        ResultSet result = statement.executeQuery(sql);
        
        while(result.next()) {
            String name = result.getString("user_name");
            System.out.println(name);
        }
        
        result.close();
        conn.close();
    }
    
}
